home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / libiberty / strstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-24  |  1.5 KB  |  62 lines

  1. /* Simple implementation of strstr for systems without it.
  2.    Copyright (C) 1991 Free Software Foundation, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /*
  19.  
  20. NAME
  21.  
  22.     strstr -- locate first occurance of a substring
  23.  
  24. SYNOPSIS
  25.  
  26.     #include <string.h>
  27.  
  28.     char *strstr (char *s1, char *s2)
  29.  
  30. DESCRIPTION
  31.  
  32.     Locates the first occurance in the string pointed to by S1 of
  33.     the string pointed to by S2.  Returns a pointer to the substring
  34.     found, or a NULL pointer if not found.  If S2 points to a string
  35.     with zero length, the function returns S1.
  36.     
  37. BUGS
  38.  
  39. */
  40.  
  41.  
  42. /* FIXME:  The above description is ANSI compiliant.  This routine has not
  43.    been validated to comply with it.  -fnf */
  44.  
  45. char *
  46. strstr (s1, s2)
  47.   char *s1, *s2;
  48. {
  49.   register char *p = s1 - 1;
  50.   extern char *strchr ();
  51.   extern int strcmp ();
  52.  
  53.   while (0 != (p = strchr (p+1, *s2)))
  54.     {
  55.       if (strcmp (p, s2))
  56.     {
  57.       return (p);
  58.     }
  59.     }
  60.   return (0);
  61. }
  62.